package model

import (
	"gorm.io/gorm"
	"member-srv/basic/config"
	"time"
)

type User struct {
	Id         uint32         `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	Mobile     string         `gorm:"column:mobile;type:char(11);comment:账号;not null;" json:"mobile"`                  // 账号
	Password   string         `gorm:"column:password;type:char(32);comment:密码;not null;" json:"password"`              // 密码
	Name       string         `gorm:"column:name;type:varchar(30);comment:昵称;not null;" json:"name"`                   // 昵称
	Image      string         `gorm:"column:image;type:varchar(300);comment:头像;not null;default:默认;" json:"image"`     // 头像
	MemberTime time.Time      `gorm:"column:member_time;type:datetime(3);comment:会员过期时间;not null;" json:"member_time"` // 会员过期时间
	CreatedAt  time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt  time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt  gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (u *User) TableName() string {
	return "user"
}

func (u *User) CreateUser() error {
	return config.DB.Create(&u).Error
}
